<template>
  <div id="shop-item">
    <div class="item-selector">
      <check-button :is-checked="itemInfo.checked" @click.native="checkClick"></check-button>
    </div>

    <div class="item-img">
      <img v-lazy="itemInfo.image" alt="商品图片" />
    </div>

    <div class="item-info">
      <div class="item-title">{{itemInfo.title}}</div>
      <div class="item-desc">商品描述: {{itemInfo.desc}}</div>
      <div class="info-bottom">
        <div class="item-price left">¥{{itemInfo.price}}</div>
        <div class="item-count right">x{{itemInfo.count}}</div>
      </div>
    </div>
  </div>
</template>

<script>
// 选中按钮组件
import CheckButton from "./CheckButton";

export default {
  name: "CartListItem",

  components: {
    CheckButton,
  },

  props: {
    itemInfo: {
      type: Object,
      default() {
        return {};
      },
    },
  },

  methods: {
    checkClick() {
      this.itemInfo.checked = !this.itemInfo.checked;
    },
  },
};
</script>

<style lang="less" scoped>
#shop-item {
  margin-bottom: 15px;
  display: flex;
  width: 100%;
  padding: 5px;
  font-size: 0;
  border-bottom: 2px solid rgba(0, 0, 0, 0.1);
  // 是否选中按钮样式
  .item-selector {
    display: flex;
    width: 18%;
    align-items: center;
    justify-content: center;
  }
  // 商品图片样式
  .item-img {
    padding: 5px;
    img {
      display: block;
      width: 80px;
      height: 100px;
      border-radius: 5px;
    }
  }
  // 商品信息
  .item-info {
    position: relative;
    padding: 5px 10px;
    color: #333333;
    font-size: 17px;
    overflow: hidden;
    .item-title,
    .item-desc {
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }
    .item-desc {
      font-size: 14px;
      color: #666666;
      margin-top: 15px;
    }
  }
  // 底部价格、数量
  .info-bottom {
    margin-top: 10px;
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    .item-price {
      color: orangered;
    }
  }
}
</style>